<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table class="form" id="form">
    <tr>
        <td class="formTitle">内容分类<font face="宋体">*</font></td>
        <td class="formValue">
            <select style="width: 150px" class="form-control"
                    isvalid="yes" id="type" onchange="func()">
                <option value="0" disabled selected>请选择</option>
                <option value="1">业务介绍</option>
                <option value="2">时限查询</option>
                <option value="3">违禁品查询</option>
                <option value="4">海关政策</option>
                <option value="5">常见问题</option>
            </select>
        </td>
    </tr>
    <tr>
        <td class="formTitle">业务标题名称<font face="宋体">*</font></td>
        <td class="formValue">
            <select id="mySelect" style="width: 150px" autocomplete="off">
            </select>
        </td>
    </tr>
    <tr>
        <td class="formTitle">消息标题<font face="宋体">*</font></td>
        <td class="formValue">
            <input type="text" id="messageTitle" class="form-control" placeholder="消息标题" isvalid="yes"
                   checkexpession="NotNull">
        </td>
    </tr>
</table>
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/js/base/message/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/js/base/message/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="${ctxPath}/static/js/base/message/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="${ctxPath}/static/libs/jquery.min.js"></script>
<script type="text/javascript" src="${ctxPath}/static/libs/bootstrap.min.js"></script>
<link href="${ctxPath}/static/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script id="editor" type="text/plain" name="gdesc" style="width:100%;height:350px;"></script>

<input type="button" id="doSubmit" value="确定">
<input type="button" id="cancel" value="取消">

<script type="text/javascript">
    var ue = UE.getEditor('editor', {});

    function func(){
        var index = $("#type").val();
        $.ajax({
            url: '../../rest/business/type/list?contentId=' + index,
            type: 'get',
            success: function (data) {
                $("#mySelect").empty();
                for (var i = 0; i < data.rows.length; i++) {
                    $("#mySelect").append(('<option value='+data.rows[i].businessId+'>'+data.rows[i].businessName+'</option>'));
                }
            }
        })
    }
    $(document).ready(function () {
        $("#doSubmit").click(function () {
            var contentId = $("#type").val();
            var businessId = $("#mySelect").val();
            var messageTitle = $("#messageTitle").val();
            var messageData = UE.getEditor('editor').getContent();
            if (!contentId) {
                alert("内容分类不能为空");
            } else if (!businessId) {
                alert("业务标题名称不能为空");
            } else if (!messageTitle) {
                alert("消息标题不能为空");
            } else if (!messageData) {
                alert("消息内容不能为空");
            } else if (messageTitle.length > 30) {
                alert("消息标题过长");
            } else {
                var message = {
                    contentId: contentId,
                    businessId: businessId,
                    messageTitle: messageTitle,
                    messageData: messageData
                };
                $.ajax({
                    url: '../../rest/message/save',
                    type: 'post',
                    contentType: 'application/json',
                    data: JSON.stringify(message),
                    success: function (data) {
                        if (data.code === 0) {
                            window.location.href = "/base/message/list.html";
                        } else {
                            alert(data.msg)
                        }
                    },
                })
            }
        })
        $("#cancel").click(function () {
            window.location.href = "/base/message/list.html";
        })
    })
</script>
</body>
</html>